package cn.jcet.service.impl;

import cn.jcet.constants.Constants;
import cn.jcet.domain.SimpleUser;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.jcet.domain.Menu;
import cn.jcet.mapper.MenuMapper;
import cn.jcet.service.MenuService;
@Service
public class MenuServiceImpl implements MenuService{

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public List<Menu> selectMenuTree(boolean isAdmin, SimpleUser simpleUser) {
        QueryWrapper<Menu> wrapper = new QueryWrapper<>();
        // 查询状态是否可用
        wrapper.eq(Menu.COL_STATUS,Constants.STATUS_TRUE);
        // 只查询菜单类型
        wrapper.in(Menu.COL_MENU_TYPE,Constants.MENU_TYPE_M,Constants.MENU_TYPE_C);
        // 根据什么排序
        wrapper.orderByAsc(Menu.COL_PARENT_ID);
        //  如果isAdmin为true那么查询全部，否则根据用户id查询
        if (isAdmin){
            // 查询管理员权限
            menuMapper.selectList(wrapper);
        }else {
            //TODO 根据用户去id和权限查询
            return menuMapper.selectList(wrapper);
        }
        return null;
    }
}
